def uwu(a):   
    if a==1: return False   
    test=True   
    k=a-1   
    while k>1:   
        if not a%k:   
            test = False               
            break   
        k-=1       
    return test  
     
n=input() 
r=[] 
for i in range(len(n)+1): 
    for k in range(i,len(n)+1): 
        if i==k: 
            continue 
        a=int(n[i:k]) 
        if uwu(a): 
            r+=[a] 
print(max(r) if r else 0)
